<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="layout.css" />
<title>Register</title>
</head>

<body>
<div id="container">
<div id="logo"><img src="images/logo.png" alt="Logo" height="117" width="619" /></div>
<div id="nav">
<ul>
        <li><a href="index.php">Home</a></li>
        <li><a href="products.php">Products</a></li>
        <li><a href="contact.php">Contact Me</a></li>
</ul>
</div>
<div id="content">
<form action='register.php' method='POST'>
	<table>
    	<tr>
        	<td>
            Your full name:
            </td>
            <td>
            <input type='text' name='fullname'>
            </td>
       </tr>
       <tr>
        	<td>
            Choose a username:
            </td>
            <td>
            <input type='text' name='username'>
            </td>
       </tr>
       <tr>
        	<td>
            Choose a password:
            </td>
            <td>
            <input type='password' name='password'>
            </td>
       </tr><tr>
        	<td>
            Repeat your password:
            </td>
            <td>
            <input type='password' name='repeatpassword'>
            </td>
       </tr>
    </table>
    <p>
    <input type='submit' name='Submit' value='Register' align="right">

</form>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){
$submit = strip_tags(@$_POST['submit']);
$fullname = strip_tags($_POST['fullname']);
$username = strtolower(strip_tags($_POST['username']));
$password = strip_tags($_POST['password']);
$repeatpassword = strip_tags($_POST['repeatpassword']);
$date = date("Y-m-d");

$connect = mysql_connect("localhost", "root", "pratt3284");
mysql_select_db("phplogin");

$namecheck = mysql_query("SELECT username FROM users WHERE username='$username'");
$count = mysql_num_rows($namecheck);

if($count!=0)
{
	echo "Username already exists!";
}
else{
if($fullname&&$username&&$password&&$repeatpassword)
{
	if($password==$repeatpassword)
	{
		if(strlen($username)>25 || strlen($fullname>25))
		{
			echo "Max limit for username and fullname are 25 characters";
		}
		else
		{
			if(strlen($password)>25||strlen($password)<6)
			{
				echo "Password must be between 6 and 25 characters!";
			}
			else
			{
				//register the user
				$password = md5($password);
				$repeatpassword	= md5($repeatpassword);
				
				$queryreg = mysql_query("INSERT INTO users VALUES('','$fullname','$username','$password','$date')");
				
				echo "You have been registered! <a href='index.php'>Return to login</a>";
			}
		}
	}
	else
		echo "Your passwords do not match!";
}
else
	echo "Please fill in <b>all</b> fields!";
}
}
?>
</div>

<div id="footer"><i>Copyright &copy; 2012 E-commerce site</i><br />
<a href="mailto:npratt3284@gmail.com">npratt3284@gmail.com</a></div>

</div>

</body>
</html>